package com.example.oracle.controller;

import com.example.oracle.pojo.Feedback;
import com.example.oracle.pojo.system.ResponseMap;
import com.example.oracle.pojo.system.WebCode;
import com.example.oracle.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Siaze
 * @date 2021/12/17
 */
@RestController
public class SysFeedBackController {

    @Autowired
    FeedbackService feedbackService;

    /**
     * 用户提交反馈
     * @param feedback 反馈的内容
     * @return 反馈是否成功
     */
    @PostMapping("/feedback/add")
    public ResponseMap addFeedBack(@RequestBody Feedback feedback){
        return feedbackService.insertFeedback(feedback) == 0 ? ResponseMap.create(WebCode.REQUEST_FAIL) : ResponseMap.create(WebCode.REQUEST_SUCCESS);
    }

    /**
     * 获取反馈列表
     * @return 所有反馈
     */
    @GetMapping("/feedback/list")
    public ResponseMap getFeedBacks(){
        ResponseMap responseMap = ResponseMap.create(WebCode.REQUEST_SUCCESS);
        responseMap.putValue("list", feedbackService.selectFeedback(null));
        return responseMap;
    }

}
